# 学生管理系统前端构建PowerShell脚本

# 检查Docker是否可用
try {
    docker -v | Out-Null
} catch {
    Write-Host "错误: Docker未安装或未启动！" -ForegroundColor Red
    pause
    exit 1
}

# 创建docker目录的绝对路径
$dockerDir = Join-Path -Path $PSScriptRoot -ChildPath "docker"

# 切换到docker目录
try {
    Set-Location -Path $dockerDir -ErrorAction Stop
} catch {
    Write-Host "错误: 无法切换到docker目录！" -ForegroundColor Red
    pause
    exit 1
}

# 构建并启动所有服务
Write-Host "正在构建并启动系统服务..." -ForegroundColor Green
try {
    docker-compose up -d --build
} catch {
    Write-Host "错误: 构建或启动失败！" -ForegroundColor Red
    pause
    exit 1
}

# 显示服务状态
Write-Host "`n服务启动成功！状态如下：" -ForegroundColor Green
docker-compose ps

# 显示访问信息
Write-Host "`n系统访问信息：" -ForegroundColor Green
Write-Host "前端地址: http://localhost:80"
Write-Host "后端API文档: http://localhost:5000/swagger/index.html"

Write-Host "`n默认管理员账号：admin" -ForegroundColor Green

Write-Host "`n按任意键退出..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')